package fr.n7.sma.model;

public class AttractorEffect {

	public static float compute(Attractor<?> attractor, int x, int y) {
		short[] centerPos = attractor.getCenter().getPosition();
		float rayon = attractor.getRadius();
		
		short xc = centerPos[0];
		short yc = centerPos[1];
		
		int x2 = xc-x;
		x2 *= x2;

		int y2 = yc-y;
		y2 *= y2;
		
		float norm = (float) Math.sqrt(x2+y2);
		
		float force;
		
		if(norm < rayon) {
			force = ((rayon - norm)/(float)rayon) * attractor.getForce();
		} else {
			force = 0;
		}
		
		return force;
	}
	
}
